﻿var gulp = require('gulp');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var packageJSON  = require('./package');

var jshintConfig = packageJSON.jshintConfig;

var jsPath =  ['src/js/common/String.js',
    'src/js/common/Array.js',
    'src/js/common/Date.js',
    'src/js/common/Type.js',
    'src/js/common/Util.js',
    'src/js/common/Map.js',
];

gulp.task('help',function () {

    console.log('	gulp build			文件打包');

    console.log('	gulp help			gulp参数说明');

    console.log('	gulp lint			Js语法检查');

    console.log('	gulp clean			清空目录');

});

gulp.task('lint', function() {
    gulp.src('src/js/common/**/*.js')
        .pipe(jshint(jshintConfig))
        .pipe(jshint.reporter('default'));
});

gulp.task('clean',function(){
    return gulp.src('./dist',{ read : false})       //src的第二个参数的{read:false}，是不读取文件,加快程序。
        .pipe(clean());
});

gulp.task('common_dev', function() {
    gulp.src(jsPath)
        .pipe(concat('common.js'))
        .pipe(gulp.dest('./dist/dev/common'));
});

gulp.task('common_prod', function() {
    gulp.src(jsPath)
        .pipe(concat('common.js'))
        .pipe(uglify())    //压缩
        .pipe(gulp.dest('./dist/prod/common'));
});


gulp.task('build', function() {
    gulp.run('common_dev','common_prod');
});

gulp.task('default', function() {
    gulp.start('build');
});